package com.beagle.njddapp.ui.activity.owner;

import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.beagle.njddapp.R;
import com.beagle.njddapp.base.BaseMvpActivity;
import com.beagle.njddapp.bean.ZdBean;
import com.beagle.njddapp.bean.owner.DIrverOrderBean;
import com.beagle.njddapp.bean.owner.NjBean;
import com.beagle.njddapp.ui.presenter.AddDirverPresenter;
import com.beagle.njddapp.ui.view.AddDirverView;
import com.beagle.njddapp.utils.StatusBarUtil;
import com.beagle.njddapp.weight.dialog.NjListDIalog;
import com.blankj.utilcode.util.ToastUtils;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author hxx
 * @date 2021-03-02 22:31
 * 添加农机驾驶员
 */
public class AddDirverDetailActivity extends BaseMvpActivity<AddDirverView, AddDirverPresenter> implements AddDirverView, NjListDIalog.onNjDialogItemClickLisenter {


    @BindView(R.id.commom_title_tv)
    TextView tvTitle;
    @BindView(R.id.common_container)
    RelativeLayout container;
    @BindView(R.id.common_tv_right)
    TextView tvRight;
    @BindView(R.id.tv_choose_device)
    TextView tvDevice;
    @BindView(R.id.tv_choose_type)
    TextView tvType;
    @BindView(R.id.tv_choose_time)
    TextView tvTime;
    @BindView(R.id.tv_choose_time_end)
    TextView tvTimeEnd;
    @BindView(R.id.ed_address)
    TextView edAdress;
    @BindView(R.id.ed_money)
    TextView edMoney;
    @BindView(R.id.tv_next)
    TextView tvNext;
    @BindView(R.id.rl_user)
    RelativeLayout rlUser;
    @BindView(R.id.ed_user)
    TextView edUser;
    @BindView(R.id.ed_user_phone)
    TextView edUserPhone;
    @BindView(R.id.rl_user_phone)
    RelativeLayout rlUserPhone;
    @BindView(R.id.prograssBar)
    ProgressBar progressBar;

    private DIrverOrderBean dirverBean;


    @Override
    public int getLayoutId() {
        return R.layout.activity_add_dirver_detail;
    }

    @Override
    public void init() {
        StatusBarUtil.immersive(this, Color.WHITE);
        StatusBarUtil.darkMode(this);
        tvTitle.setText("作业订单详情");
        dirverBean= (DIrverOrderBean) getIntent().getSerializableExtra("data");
        if(dirverBean==null){
            finish();
            return;
        }
        tvDevice.setText(dirverBean.getMeshNum());
        tvType.setText(dirverBean.getWorkTypeName());
        tvTime.setText(dirverBean.getBeginDate());
        tvTimeEnd.setText(dirverBean.getEndDate());
        edAdress.setText(dirverBean.getWorkAddress());
        edMoney.setText(dirverBean.getWorkPrice());
        if (1==(dirverBean.getOrderStatus())){
            tvRight.setText("修改");
            tvNext.setVisibility(View.VISIBLE);
            tvNext.setText("取消订单");
            tvNext.setBackgroundResource(R.drawable.bg_btn_cancle);
        }else  if (2==dirverBean.getOrderStatus()){
            tvNext.setVisibility(View.VISIBLE);
            rlUser.setVisibility(View.VISIBLE);
            rlUserPhone.setVisibility(View.VISIBLE);
            edUser.setText(dirverBean.getReceiver());
            edUserPhone.setText(dirverBean.getReceiverPhone());
        }else {
            rlUser.setVisibility(View.VISIBLE);
            rlUserPhone.setVisibility(View.VISIBLE);
            edUser.setText(dirverBean.getReceiver());
            edUserPhone.setText(dirverBean.getReceiverPhone());

        }
    }

    @Override
    public AddDirverView getMvpView() {
        return this;
    }

    @Override
    public AddDirverPresenter createPresenter() {
        return new AddDirverPresenter();
    }

    @Override
    public void onError(String message) {
        progressBar.setVisibility(View.GONE);
        ToastUtils.showShort(message);
    }
    @OnClick({R.id.common_back_iv,R.id.common_tv_right,R.id.tv_next})
    public void onCLick(View view){
        switch (view.getId()){
            case R.id.common_back_iv:
                onBackPressed();
                break;
            case R.id.tv_next:
                progressBar.setVisibility(View.VISIBLE);
                if ("取消订单".equals(tvNext.getText().toString())){
                    dirverBean.setOrderStatus(0);
                    presenter.updateFindDriverOrder(dirverBean);
                    return;
                }
                dirverBean.setOrderStatus(3);
                presenter.updateFindDriverOrder(dirverBean);
                break;
            case R.id.common_tv_right:
                startActivity(new Intent(this,AddDirverActivity.class).putExtra("data",dirverBean));
                finish();

                break;
        }
    }


    @Override
    public void addSuccess() {
        progressBar.setVisibility(View.GONE);
        setResult(306);
        finish();
    }

    @Override
    public void showRunNj(List<NjBean> results) {
    }

    @Override
    public void updateSuccess() {
        progressBar.setVisibility(View.GONE);
        ToastUtils.showShort("操作成功");
        finish();
    }

    @Override
    public void showZd(List<ZdBean> items) {

    }

    @Override
    public void onItemClick(NjBean njBean) {
        tvDevice.setText(njBean.getMeshNum());
    }
}
